In [1]:
import glob
import math
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
import random
import sklearn.metrics as metrics

from tensorflow.keras import optimizers
from tensorflow.keras.callbacks import ModelCheckpoint, CSVLogger, LearningRateScheduler
from tensorflow.keras.models import Model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import add, concatenate, Conv2D, Dense, Dropout, Flatten, Input
from tensorflow.keras.layers import Activation, AveragePooling2D, BatchNormalization, MaxPooling2D
from tensorflow.keras.regularizers import l2
from tensorflow.keras.utils import to_categorical


%matplotlib inline
In [2]:
                            # Set up 'ggplot' style
plt.style.use('ggplot')     # if want to use the default style, set 'classic'
plt.rcParams['ytick.right']     = True
plt.rcParams['ytick.labelright']= True
plt.rcParams['ytick.left']      = False
plt.rcParams['ytick.labelleft'] = False
plt.rcParams['font.family']     = 'Arial'
In [3]:
# where am i?
%pwd
Out[3]:
'C:\\Users\\david\\Documents\\ImageNet'
In [4]:
flowers = glob.glob('./data/flr_*.jpg')
fungus = glob.glob('./data/fgs_*.jpg')
rocks = glob.glob('./data/rck_*.jpg')

pixel_flowers = glob.glob('./data/pxl_flower_*.jpeg')
pixel_umbrella = glob.glob('./data/pxl_umbrella_*.jpeg')
print("There are %s, %s flower, %s fungus, %s rock and %s umbrella pictures" %(len(flowers), len(pixel_flowers), len(fungus), len(rocks), len(pixel_umbrella)))
There are 1269, 1792 flower, 856 fungus, 1007 rock and 420 umbrella pictures
In [5]:
# Randomly show 10 examples of the images
from IPython.display import Image
    
dataset = flowers #flowers #fungus #rocks

for i in range(0, 5):
    index = random.randint(0, len(dataset)-1)   
    print("Showing:", dataset[index])
    
    img = mpimg.imread(dataset[index])
    imgplot = plt.imshow(img)
    plt.show()

#Image(dataset[index])
Showing: ./data\flr_01665.jpg
Showing: ./data\flr_00345.jpg
Showing: ./data\flr_01323.jpg
Showing: ./data\flr_01586.jpg
Showing: ./data\flr_01873.jpg

Extract the training and testing datasets

In [6]:
# Load the data
trDatOrg       = np.load('flrnonflr-train-imgs96-0.8.npz')['arr_0']
trLblOrg       = np.load('flrnonflr-train-labels96-0.8.npz')['arr_0']
tsDatOrg       = np.load('flrnonflr-test-imgs96-0.8.npz')['arr_0']
tsLblOrg       = np.load('flrnonflr-test-labels96-0.8.npz')['arr_0']
In [7]:
print("For the training and test datasets:")
print("The shapes are %s, %s, %s, %s" \
      %(trDatOrg.shape, trLblOrg.shape, tsDatOrg.shape, tsLblOrg.shape))
For the training and test datasets:
The shapes are (4264, 96, 96, 3), (4264,), (1067, 96, 96, 3), (1067,)
In [8]:
# Randomly show 10 examples of the images

data = tsDatOrg
label = tsLblOrg

for i in range(20):
    index = random.randint(0, len(data)-1)
    print("Showing %s index image, It is %s" %(index, label[index]))
    imgplot = plt.imshow(data[index])
    plt.show()
Showing 686 index image, It is 0.0
Showing 773 index image, It is 0.0
Showing 421 index image, It is 1.0
Showing 883 index image, It is 0.0
Showing 1039 index image, It is 0.0
Showing 371 index image, It is 1.0
Showing 835 index image, It is 0.0
Showing 124 index image, It is 1.0
Showing 401 index image, It is 1.0
Showing 479 index image, It is 1.0
Showing 781 index image, It is 0.0
Showing 787 index image, It is 0.0
Showing 861 index image, It is 0.0
Showing 1045 index image, It is 0.0
Showing 835 index image, It is 0.0
Showing 88 index image, It is 1.0
Showing 133 index image, It is 1.0
Showing 70 index image, It is 1.0
Showing 989 index image, It is 0.0
Showing 848 index image, It is 0.0
In [9]:
# Convert the data into 'float32'
# Rescale the values from 0~255 to 0~1
trDat       = trDatOrg.astype('float32')/255
tsDat       = tsDatOrg.astype('float32')/255

# Retrieve the row size of each image
# Retrieve the column size of each image
imgrows     = trDat.shape[1]
imgclms     = trDat.shape[2]
channel     = 3

# # reshape the data to be [samples][width][height][channel]
# # This is required by Keras framework
# trDat       = trDat.reshape(trDat.shape[0], imgrows, imgclms, channel)
# tsDat       = tsDat.reshape(tsDat.shape[0], imgrows, imgclms, channel)

# Perform one hot encoding on the labels
# Retrieve the number of classes in this problem
trLbl       = to_categorical(trLblOrg)
tsLbl       = to_categorical(tsLblOrg)
num_classes = tsLbl.shape[1]
In [10]:
# fix random seed for reproducibility
seed = 29
np.random.seed(seed)


modelname = 'FlowerPower'

def createBaselineModel():
    inputs = Input(shape=(imgrows, imgclms, channel))
    x = Conv2D(30, (4, 4), activation='relu')(inputs)
    x = MaxPooling2D(pool_size=(2, 2))(x)
    x = Conv2D(50, (4, 4), activation='relu')(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)
    x = Dropout(0.3)(x)
    x = Flatten()(x)
    x = Dense(32, activation='relu')(x)
    x = Dense(num_classes, activation='softmax')(x)
    
    model = Model(inputs=[inputs],outputs=x)
    
    model.compile(loss='categorical_crossentropy', 
                  optimizer='adam',
                  metrics=['accuracy'])
    return model

optmz       = optimizers.Adam(lr=0.001)

def resLyr(inputs,
           numFilters=16,
           kernelSz=3,
           strides=1,
           activation='relu',
           batchNorm=True,
           convFirst=True,
           lyrName=None):
    convLyr = Conv2D(numFilters, kernel_size=kernelSz, strides=strides, 
                     padding='same', kernel_initializer='he_normal', 
                     kernel_regularizer=l2(1e-4), 
                     name=lyrName+'_conv' if lyrName else None)
    x = inputs
    if convFirst:
        x = convLyr(x)
        if batchNorm:
            x = BatchNormalization(name=lyrName+'_bn' if lyrName else None)(x)
        if activation is not None:
            x = Activation(activation,name=lyrName+'_'+activation if lyrName else None)(x)
    else:
        if batchNorm:
            x = BatchNormalization(name=lyrName+'_bn' if lyrName else None)(x)
        if activation is not None:
            x = Activation(activation, name=lyrName+'_'+activation if lyrName else None)(x)
        x = convLyr(x)
    return x


def resBlkV1(inputs,
             numFilters=16,
             numBlocks=3,
             downsampleOnFirst=True,
             names=None):
    x = inputs
    for run in range(0,numBlocks):
        strides = 1
        blkStr = str(run+1)
        if downsampleOnFirst and run == 0:
            strides = 2
        y = resLyr(inputs=x, numFilters=numFilters, strides=strides,
                   lyrName=names+'_Blk'+blkStr+'_Res1' if names else None)
        y = resLyr(inputs=y, numFilters=numFilters, activation=None,
                   lyrName=names+'_Blk'+blkStr+'_Res2' if names else None)
        if downsampleOnFirst and run == 0:
            x = resLyr(inputs=x, numFilters=numFilters, kernelSz=1,
                       strides=strides, activation=None, batchNorm=False,
                       lyrName=names+'_Blk'+blkStr+'_lin' if names else None)
        x = add([x,y], name=names+'_Blk'+blkStr+'_add' if names else None)
        x = Activation('relu', name=names+'_Blk'+blkStr+'_relu' if names else None)(x)
    return x

def createResNetV1(inputShape=(imgrows, imgclms, channel),
                   numClasses=2):
    inputs = Input(shape=inputShape)
    v = resLyr(inputs, lyrName='Inpt')
    v = resBlkV1(inputs=v, numFilters=16, numBlocks=3,
                 downsampleOnFirst=False, names='Stg1')
    v = Dropout(0.20)(v)
    v = resBlkV1(inputs=v, numFilters=32, numBlocks=3,
                 downsampleOnFirst=True, names='Stg2')
    v = Dropout(0.25)(v)
    v = resBlkV1(inputs=v, numFilters=64, numBlocks=3,
                 downsampleOnFirst=True, names='Stg3')
    v = Dropout(0.30)(v)
    v = AveragePooling2D(pool_size=8, name='AvgPool')(v)
    v = Flatten()(v) 
    outputs = Dense(numClasses, activation='softmax', 
                    kernel_initializer='he_normal')(v)
    model = Model(inputs=inputs,outputs=outputs)
    model.compile(loss='categorical_crossentropy', optimizer=optmz, 
                  metrics=['accuracy'])
    return model



# Setup the models
model       = createResNetV1() # This is meant for training
modelGo     = createResNetV1() # This is used for final testing

model.summary()
WARNING:tensorflow:From D:\DocumentsDDrive\Installed_Files\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\keras\initializers.py:104: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with distribution=normal is deprecated and will be removed in a future version.
Instructions for updating:
`normal` is a deprecated alias for `truncated_normal`
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            (None, 96, 96, 3)    0                                            
__________________________________________________________________________________________________
Inpt_conv (Conv2D)              (None, 96, 96, 16)   448         input_1[0][0]                    
__________________________________________________________________________________________________
Inpt_bn (BatchNormalization)    (None, 96, 96, 16)   64          Inpt_conv[0][0]                  
__________________________________________________________________________________________________
Inpt_relu (Activation)          (None, 96, 96, 16)   0           Inpt_bn[0][0]                    
__________________________________________________________________________________________________
Stg1_Blk1_Res1_conv (Conv2D)    (None, 96, 96, 16)   2320        Inpt_relu[0][0]                  
__________________________________________________________________________________________________
Stg1_Blk1_Res1_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk1_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk1_Res1_relu (Activation (None, 96, 96, 16)   0           Stg1_Blk1_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk1_Res2_conv (Conv2D)    (None, 96, 96, 16)   2320        Stg1_Blk1_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg1_Blk1_Res2_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk1_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk1_add (Add)             (None, 96, 96, 16)   0           Inpt_relu[0][0]                  
                                                                 Stg1_Blk1_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk1_relu (Activation)     (None, 96, 96, 16)   0           Stg1_Blk1_add[0][0]              
__________________________________________________________________________________________________
Stg1_Blk2_Res1_conv (Conv2D)    (None, 96, 96, 16)   2320        Stg1_Blk1_relu[0][0]             
__________________________________________________________________________________________________
Stg1_Blk2_Res1_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk2_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk2_Res1_relu (Activation (None, 96, 96, 16)   0           Stg1_Blk2_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk2_Res2_conv (Conv2D)    (None, 96, 96, 16)   2320        Stg1_Blk2_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg1_Blk2_Res2_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk2_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk2_add (Add)             (None, 96, 96, 16)   0           Stg1_Blk1_relu[0][0]             
                                                                 Stg1_Blk2_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk2_relu (Activation)     (None, 96, 96, 16)   0           Stg1_Blk2_add[0][0]              
__________________________________________________________________________________________________
Stg1_Blk3_Res1_conv (Conv2D)    (None, 96, 96, 16)   2320        Stg1_Blk2_relu[0][0]             
__________________________________________________________________________________________________
Stg1_Blk3_Res1_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk3_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk3_Res1_relu (Activation (None, 96, 96, 16)   0           Stg1_Blk3_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk3_Res2_conv (Conv2D)    (None, 96, 96, 16)   2320        Stg1_Blk3_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg1_Blk3_Res2_bn (BatchNormali (None, 96, 96, 16)   64          Stg1_Blk3_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg1_Blk3_add (Add)             (None, 96, 96, 16)   0           Stg1_Blk2_relu[0][0]             
                                                                 Stg1_Blk3_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg1_Blk3_relu (Activation)     (None, 96, 96, 16)   0           Stg1_Blk3_add[0][0]              
__________________________________________________________________________________________________
dropout (Dropout)               (None, 96, 96, 16)   0           Stg1_Blk3_relu[0][0]             
__________________________________________________________________________________________________
Stg2_Blk1_Res1_conv (Conv2D)    (None, 48, 48, 32)   4640        dropout[0][0]                    
__________________________________________________________________________________________________
Stg2_Blk1_Res1_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk1_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk1_Res1_relu (Activation (None, 48, 48, 32)   0           Stg2_Blk1_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk1_Res2_conv (Conv2D)    (None, 48, 48, 32)   9248        Stg2_Blk1_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg2_Blk1_lin_conv (Conv2D)     (None, 48, 48, 32)   544         dropout[0][0]                    
__________________________________________________________________________________________________
Stg2_Blk1_Res2_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk1_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk1_add (Add)             (None, 48, 48, 32)   0           Stg2_Blk1_lin_conv[0][0]         
                                                                 Stg2_Blk1_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk1_relu (Activation)     (None, 48, 48, 32)   0           Stg2_Blk1_add[0][0]              
__________________________________________________________________________________________________
Stg2_Blk2_Res1_conv (Conv2D)    (None, 48, 48, 32)   9248        Stg2_Blk1_relu[0][0]             
__________________________________________________________________________________________________
Stg2_Blk2_Res1_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk2_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk2_Res1_relu (Activation (None, 48, 48, 32)   0           Stg2_Blk2_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk2_Res2_conv (Conv2D)    (None, 48, 48, 32)   9248        Stg2_Blk2_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg2_Blk2_Res2_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk2_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk2_add (Add)             (None, 48, 48, 32)   0           Stg2_Blk1_relu[0][0]             
                                                                 Stg2_Blk2_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk2_relu (Activation)     (None, 48, 48, 32)   0           Stg2_Blk2_add[0][0]              
__________________________________________________________________________________________________
Stg2_Blk3_Res1_conv (Conv2D)    (None, 48, 48, 32)   9248        Stg2_Blk2_relu[0][0]             
__________________________________________________________________________________________________
Stg2_Blk3_Res1_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk3_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk3_Res1_relu (Activation (None, 48, 48, 32)   0           Stg2_Blk3_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk3_Res2_conv (Conv2D)    (None, 48, 48, 32)   9248        Stg2_Blk3_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg2_Blk3_Res2_bn (BatchNormali (None, 48, 48, 32)   128         Stg2_Blk3_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg2_Blk3_add (Add)             (None, 48, 48, 32)   0           Stg2_Blk2_relu[0][0]             
                                                                 Stg2_Blk3_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg2_Blk3_relu (Activation)     (None, 48, 48, 32)   0           Stg2_Blk3_add[0][0]              
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None, 48, 48, 32)   0           Stg2_Blk3_relu[0][0]             
__________________________________________________________________________________________________
Stg3_Blk1_Res1_conv (Conv2D)    (None, 24, 24, 64)   18496       dropout_1[0][0]                  
__________________________________________________________________________________________________
Stg3_Blk1_Res1_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk1_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk1_Res1_relu (Activation (None, 24, 24, 64)   0           Stg3_Blk1_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk1_Res2_conv (Conv2D)    (None, 24, 24, 64)   36928       Stg3_Blk1_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg3_Blk1_lin_conv (Conv2D)     (None, 24, 24, 64)   2112        dropout_1[0][0]                  
__________________________________________________________________________________________________
Stg3_Blk1_Res2_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk1_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk1_add (Add)             (None, 24, 24, 64)   0           Stg3_Blk1_lin_conv[0][0]         
                                                                 Stg3_Blk1_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk1_relu (Activation)     (None, 24, 24, 64)   0           Stg3_Blk1_add[0][0]              
__________________________________________________________________________________________________
Stg3_Blk2_Res1_conv (Conv2D)    (None, 24, 24, 64)   36928       Stg3_Blk1_relu[0][0]             
__________________________________________________________________________________________________
Stg3_Blk2_Res1_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk2_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk2_Res1_relu (Activation (None, 24, 24, 64)   0           Stg3_Blk2_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk2_Res2_conv (Conv2D)    (None, 24, 24, 64)   36928       Stg3_Blk2_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg3_Blk2_Res2_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk2_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk2_add (Add)             (None, 24, 24, 64)   0           Stg3_Blk1_relu[0][0]             
                                                                 Stg3_Blk2_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk2_relu (Activation)     (None, 24, 24, 64)   0           Stg3_Blk2_add[0][0]              
__________________________________________________________________________________________________
Stg3_Blk3_Res1_conv (Conv2D)    (None, 24, 24, 64)   36928       Stg3_Blk2_relu[0][0]             
__________________________________________________________________________________________________
Stg3_Blk3_Res1_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk3_Res1_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk3_Res1_relu (Activation (None, 24, 24, 64)   0           Stg3_Blk3_Res1_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk3_Res2_conv (Conv2D)    (None, 24, 24, 64)   36928       Stg3_Blk3_Res1_relu[0][0]        
__________________________________________________________________________________________________
Stg3_Blk3_Res2_bn (BatchNormali (None, 24, 24, 64)   256         Stg3_Blk3_Res2_conv[0][0]        
__________________________________________________________________________________________________
Stg3_Blk3_add (Add)             (None, 24, 24, 64)   0           Stg3_Blk2_relu[0][0]             
                                                                 Stg3_Blk3_Res2_bn[0][0]          
__________________________________________________________________________________________________
Stg3_Blk3_relu (Activation)     (None, 24, 24, 64)   0           Stg3_Blk3_add[0][0]              
__________________________________________________________________________________________________
dropout_2 (Dropout)             (None, 24, 24, 64)   0           Stg3_Blk3_relu[0][0]             
__________________________________________________________________________________________________
AvgPool (AveragePooling2D)      (None, 3, 3, 64)     0           dropout_2[0][0]                  
__________________________________________________________________________________________________
flatten (Flatten)               (None, 576)          0           AvgPool[0][0]                    
__________________________________________________________________________________________________
dense (Dense)                   (None, 2)            1154        flatten[0][0]                    
==================================================================================================
Total params: 274,946
Trainable params: 273,570
Non-trainable params: 1,376
__________________________________________________________________________________________________
In [11]:
# Create checkpoint for the training
# This checkpoint performs model saving when
# an epoch gives highest testing accuracy
# filepath        = modelname + ".hdf5"
# checkpoint      = ModelCheckpoint(filepath, 
#                                   monitor='val_acc', 
#                                   verbose=0, 
#                                   save_best_only=True, 
#                                   mode='max')

#                             # Log the epoch detail into csv
# csv_logger      = CSVLogger(modelname +'.csv')
# callbacks_list  = [checkpoint,csv_logger]

def lrSchedule(epoch):
    lr  = 1e-3
    
    if epoch > 70:
        lr  *= 0.5e-3
        
    elif epoch > 50:
        lr  *= 1e-3
        
    elif epoch > 40:
        lr  *= 1e-2
        
    elif epoch > 30:
        lr  *= 1e-1
        
    print('Learning rate: ', lr)
    
    return lr

LRScheduler     = LearningRateScheduler(lrSchedule)

                            # Create checkpoint for the training
                            # This checkpoint performs model saving when
                            # an epoch gives highest testing accuracy
filepath        = modelname + ".hdf5"
checkpoint      = ModelCheckpoint(filepath, 
                                  monitor='val_acc', 
                                  verbose=0, 
                                  save_best_only=True, 
                                  mode='max')

                            # Log the epoch detail into csv
csv_logger      = CSVLogger(modelname +'.csv')
callbacks_list  = [checkpoint, csv_logger, LRScheduler]
#callbacks_list  = [checkpoint, csv_logger]
In [12]:
# Fit the model
# This is where the training starts
# model.fit(trDat, 
#           trLbl, 
#           validation_data=(tsDat, tsLbl), 
#           epochs=120, 
#           batch_size=32,
#           callbacks=callbacks_list)

datagen = ImageDataGenerator(width_shift_range=0.1,
                             height_shift_range=0.1,
                             rotation_range=30,
                             horizontal_flip=True,
                             vertical_flip=False)

model.fit_generator(datagen.flow(trDat, trLbl, batch_size=32),
                    validation_data=(tsDat, tsLbl),
                    epochs=120, 
                    verbose=1,
                    steps_per_epoch=len(trDat)/32,
                    callbacks=callbacks_list)
Learning rate:  0.001
Epoch 1/120
134/133 [==============================] - 40s 301ms/step - loss: 0.7513 - acc: 0.7278 - val_loss: 0.7888 - val_acc: 0.7198
Learning rate:  0.001
Epoch 2/120
134/133 [==============================] - 25s 189ms/step - loss: 0.6174 - acc: 0.7978 - val_loss: 0.9793 - val_acc: 0.6701
Learning rate:  0.001
Epoch 3/120
134/133 [==============================] - 26s 192ms/step - loss: 0.5778 - acc: 0.8209 - val_loss: 0.6972 - val_acc: 0.6907
Learning rate:  0.001
Epoch 4/120
134/133 [==============================] - 26s 193ms/step - loss: 0.5302 - acc: 0.8400 - val_loss: 0.4937 - val_acc: 0.8613
Learning rate:  0.001
Epoch 5/120
134/133 [==============================] - 26s 195ms/step - loss: 0.5102 - acc: 0.8461 - val_loss: 0.5898 - val_acc: 0.8126
Learning rate:  0.001
Epoch 6/120
134/133 [==============================] - 26s 195ms/step - loss: 0.4794 - acc: 0.8545 - val_loss: 0.5129 - val_acc: 0.8294
Learning rate:  0.001
Epoch 7/120
134/133 [==============================] - 27s 203ms/step - loss: 0.4808 - acc: 0.8575 - val_loss: 0.4351 - val_acc: 0.8800
Learning rate:  0.001
Epoch 8/120
134/133 [==============================] - 26s 190ms/step - loss: 0.4527 - acc: 0.8643 - val_loss: 0.6384 - val_acc: 0.8229
Learning rate:  0.001
Epoch 9/120
134/133 [==============================] - 26s 191ms/step - loss: 0.4544 - acc: 0.8671 - val_loss: 0.4565 - val_acc: 0.8725
Learning rate:  0.001
Epoch 10/120
134/133 [==============================] - 26s 191ms/step - loss: 0.4353 - acc: 0.8692 - val_loss: 0.5442 - val_acc: 0.8144
Learning rate:  0.001
Epoch 11/120
134/133 [==============================] - 26s 192ms/step - loss: 0.4190 - acc: 0.8801 - val_loss: 0.5975 - val_acc: 0.8332
Learning rate:  0.001
Epoch 12/120
134/133 [==============================] - 26s 192ms/step - loss: 0.4163 - acc: 0.8720 - val_loss: 0.4123 - val_acc: 0.8885
Learning rate:  0.001
Epoch 13/120
134/133 [==============================] - 26s 191ms/step - loss: 0.3994 - acc: 0.8757 - val_loss: 0.5102 - val_acc: 0.8379
Learning rate:  0.001
Epoch 14/120
134/133 [==============================] - 26s 194ms/step - loss: 0.3893 - acc: 0.8883 - val_loss: 0.5228 - val_acc: 0.8454
Learning rate:  0.001
Epoch 15/120
134/133 [==============================] - 26s 191ms/step - loss: 0.3751 - acc: 0.8855 - val_loss: 0.4273 - val_acc: 0.8688
Learning rate:  0.001
Epoch 16/120
134/133 [==============================] - 26s 192ms/step - loss: 0.3693 - acc: 0.8895 - val_loss: 0.4038 - val_acc: 0.8735
Learning rate:  0.001
Epoch 17/120
134/133 [==============================] - 26s 193ms/step - loss: 0.3669 - acc: 0.8885 - val_loss: 0.4732 - val_acc: 0.8266
Learning rate:  0.001
Epoch 18/120
134/133 [==============================] - 26s 192ms/step - loss: 0.3551 - acc: 0.8969 - val_loss: 0.3755 - val_acc: 0.8894
Learning rate:  0.001
Epoch 19/120
134/133 [==============================] - 27s 198ms/step - loss: 0.3578 - acc: 0.8988 - val_loss: 0.3789 - val_acc: 0.8866
Learning rate:  0.001
Epoch 20/120
134/133 [==============================] - 26s 194ms/step - loss: 0.3457 - acc: 0.8948 - val_loss: 0.3653 - val_acc: 0.8903
Learning rate:  0.001
Epoch 21/120
134/133 [==============================] - 26s 192ms/step - loss: 0.3411 - acc: 0.8955 - val_loss: 0.3671 - val_acc: 0.8838
Learning rate:  0.001
Epoch 22/120
134/133 [==============================] - 26s 196ms/step - loss: 0.3400 - acc: 0.9000 - val_loss: 0.3491 - val_acc: 0.8988
Learning rate:  0.001
Epoch 23/120
134/133 [==============================] - 27s 202ms/step - loss: 0.3312 - acc: 0.8944 - val_loss: 0.3268 - val_acc: 0.9128
Learning rate:  0.001
Epoch 24/120
134/133 [==============================] - 26s 191ms/step - loss: 0.3171 - acc: 0.9062 - val_loss: 0.3804 - val_acc: 0.8828
Learning rate:  0.001
Epoch 25/120
134/133 [==============================] - 26s 193ms/step - loss: 0.3152 - acc: 0.9025 - val_loss: 0.4201 - val_acc: 0.8650
Learning rate:  0.001
Epoch 26/120
134/133 [==============================] - 26s 195ms/step - loss: 0.3087 - acc: 0.9048 - val_loss: 0.9063 - val_acc: 0.7001
Learning rate:  0.001
Epoch 27/120
134/133 [==============================] - 25s 190ms/step - loss: 0.3135 - acc: 0.9021 - val_loss: 0.3539 - val_acc: 0.8903
Learning rate:  0.001
Epoch 28/120
134/133 [==============================] - 26s 193ms/step - loss: 0.3012 - acc: 0.9051 - val_loss: 0.4241 - val_acc: 0.8632
Learning rate:  0.001
Epoch 29/120
134/133 [==============================] - 26s 192ms/step - loss: 0.3003 - acc: 0.9044 - val_loss: 0.3722 - val_acc: 0.8997
Learning rate:  0.001
Epoch 30/120
134/133 [==============================] - 26s 191ms/step - loss: 0.3088 - acc: 0.9056 - val_loss: 0.3314 - val_acc: 0.8978
Learning rate:  0.001
Epoch 31/120
134/133 [==============================] - 25s 190ms/step - loss: 0.3041 - acc: 0.9056 - val_loss: 0.3371 - val_acc: 0.8950
Learning rate:  0.0001
Epoch 32/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2666 - acc: 0.9244 - val_loss: 0.3102 - val_acc: 0.9072
Learning rate:  0.0001
Epoch 33/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2533 - acc: 0.9235 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  0.0001
Epoch 34/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2486 - acc: 0.9291 - val_loss: 0.3041 - val_acc: 0.9072
Learning rate:  0.0001
Epoch 35/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2489 - acc: 0.9291 - val_loss: 0.3029 - val_acc: 0.9072
Learning rate:  0.0001
Epoch 36/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2520 - acc: 0.9242 - val_loss: 0.3082 - val_acc: 0.9119
Learning rate:  0.0001
Epoch 37/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2449 - acc: 0.9314 - val_loss: 0.3349 - val_acc: 0.9007
Learning rate:  0.0001
Epoch 38/120
134/133 [==============================] - 26s 193ms/step - loss: 0.2364 - acc: 0.9354 - val_loss: 0.3068 - val_acc: 0.9082
Learning rate:  0.0001
Epoch 39/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2340 - acc: 0.9293 - val_loss: 0.3019 - val_acc: 0.9128
Learning rate:  0.0001
Epoch 40/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2450 - acc: 0.9300 - val_loss: 0.3061 - val_acc: 0.9119
Learning rate:  0.0001
Epoch 41/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2355 - acc: 0.9340 - val_loss: 0.3192 - val_acc: 0.9091
Learning rate:  1e-05
Epoch 42/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2253 - acc: 0.9375 - val_loss: 0.3068 - val_acc: 0.9091
Learning rate:  1e-05
Epoch 43/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2245 - acc: 0.9389 - val_loss: 0.3050 - val_acc: 0.9082
Learning rate:  1e-05
Epoch 44/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2348 - acc: 0.9363 - val_loss: 0.3066 - val_acc: 0.9100
Learning rate:  1e-05
Epoch 45/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2282 - acc: 0.9345 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  1e-05
Epoch 46/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2256 - acc: 0.9342 - val_loss: 0.3057 - val_acc: 0.9082
Learning rate:  1e-05
Epoch 47/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2304 - acc: 0.9387 - val_loss: 0.3082 - val_acc: 0.9091
Learning rate:  1e-05
Epoch 48/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2334 - acc: 0.9356 - val_loss: 0.3066 - val_acc: 0.9072
Learning rate:  1e-05
Epoch 49/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2255 - acc: 0.9356 - val_loss: 0.3069 - val_acc: 0.9072
Learning rate:  1e-05
Epoch 50/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2254 - acc: 0.9398 - val_loss: 0.3064 - val_acc: 0.9082
Learning rate:  1e-05
Epoch 51/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2248 - acc: 0.9342 - val_loss: 0.3073 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 52/120
134/133 [==============================] - 26s 194ms/step - loss: 0.2255 - acc: 0.9349 - val_loss: 0.3067 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 53/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2351 - acc: 0.9340 - val_loss: 0.3061 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 54/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2293 - acc: 0.9373 - val_loss: 0.3063 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 55/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2253 - acc: 0.9356 - val_loss: 0.3067 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 56/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2306 - acc: 0.9363 - val_loss: 0.3068 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 57/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2231 - acc: 0.9382 - val_loss: 0.3068 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 58/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2295 - acc: 0.9359 - val_loss: 0.3069 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 59/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2280 - acc: 0.9373 - val_loss: 0.3062 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 60/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2315 - acc: 0.9324 - val_loss: 0.3063 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 61/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2332 - acc: 0.9321 - val_loss: 0.3061 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 62/120
134/133 [==============================] - 26s 190ms/step - loss: 0.2190 - acc: 0.9396 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 63/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2240 - acc: 0.9382 - val_loss: 0.3060 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 64/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2177 - acc: 0.9398 - val_loss: 0.3064 - val_acc: 0.9063
Learning rate:  1e-06
Epoch 65/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2306 - acc: 0.9314 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 66/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2326 - acc: 0.9314 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 67/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2219 - acc: 0.9373 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 68/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2353 - acc: 0.9354 - val_loss: 0.3058 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 69/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2179 - acc: 0.9391 - val_loss: 0.3060 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 70/120
134/133 [==============================] - 26s 194ms/step - loss: 0.2337 - acc: 0.9342 - val_loss: 0.3053 - val_acc: 0.9072
Learning rate:  1e-06
Epoch 71/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2317 - acc: 0.9352 - val_loss: 0.3060 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 72/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2301 - acc: 0.9342 - val_loss: 0.3058 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 73/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2293 - acc: 0.9331 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 74/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2297 - acc: 0.9352 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 75/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2218 - acc: 0.9426 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 76/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2194 - acc: 0.9401 - val_loss: 0.3059 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 77/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2235 - acc: 0.9380 - val_loss: 0.3058 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 78/120
134/133 [==============================] - 26s 196ms/step - loss: 0.2250 - acc: 0.9375 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 79/120
134/133 [==============================] - 26s 194ms/step - loss: 0.2226 - acc: 0.9389 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 80/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2349 - acc: 0.9340 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 81/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2206 - acc: 0.9403 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 82/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2192 - acc: 0.9394 - val_loss: 0.3067 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 83/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2188 - acc: 0.9412 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 84/120
134/133 [==============================] - 26s 193ms/step - loss: 0.2329 - acc: 0.9340 - val_loss: 0.3066 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 85/120
134/133 [==============================] - 26s 191ms/step - loss: 0.2230 - acc: 0.9352 - val_loss: 0.3056 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 86/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2207 - acc: 0.9401 - val_loss: 0.3058 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 87/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2241 - acc: 0.9387 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 88/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2274 - acc: 0.9398 - val_loss: 0.3067 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 89/120
134/133 [==============================] - 26s 196ms/step - loss: 0.2281 - acc: 0.9347 - val_loss: 0.3061 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 90/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2188 - acc: 0.9391 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 91/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2235 - acc: 0.9373 - val_loss: 0.3063 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 92/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2319 - acc: 0.9359 - val_loss: 0.3066 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 93/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2235 - acc: 0.9382 - val_loss: 0.3061 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 94/120
134/133 [==============================] - 26s 195ms/step - loss: 0.2342 - acc: 0.9342 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 95/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2250 - acc: 0.9361 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 96/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2239 - acc: 0.9359 - val_loss: 0.3060 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 97/120
134/133 [==============================] - 25s 190ms/step - loss: 0.2148 - acc: 0.9387 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 98/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2315 - acc: 0.9326 - val_loss: 0.3072 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 99/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2179 - acc: 0.9377 - val_loss: 0.3074 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 100/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2293 - acc: 0.9340 - val_loss: 0.3072 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 101/120
134/133 [==============================] - 26s 196ms/step - loss: 0.2279 - acc: 0.9410 - val_loss: 0.3073 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 102/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2323 - acc: 0.9375 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 103/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2266 - acc: 0.9352 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 104/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2184 - acc: 0.9394 - val_loss: 0.3060 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 105/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2267 - acc: 0.9347 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 106/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2290 - acc: 0.9389 - val_loss: 0.3061 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 107/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2275 - acc: 0.9363 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 108/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2217 - acc: 0.9375 - val_loss: 0.3068 - val_acc: 0.9082
Learning rate:  5e-07
Epoch 109/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2238 - acc: 0.9389 - val_loss: 0.3067 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 110/120
134/133 [==============================] - 25s 188ms/step - loss: 0.2216 - acc: 0.9377 - val_loss: 0.3065 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 111/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2206 - acc: 0.9377 - val_loss: 0.3062 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 112/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2214 - acc: 0.9363 - val_loss: 0.3064 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 113/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2252 - acc: 0.9384 - val_loss: 0.3066 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 114/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2282 - acc: 0.9398 - val_loss: 0.3073 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 115/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2200 - acc: 0.9415 - val_loss: 0.3066 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 116/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2230 - acc: 0.9377 - val_loss: 0.3068 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 117/120
134/133 [==============================] - 25s 189ms/step - loss: 0.2297 - acc: 0.9366 - val_loss: 0.3067 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 118/120
134/133 [==============================] - 26s 193ms/step - loss: 0.2281 - acc: 0.9333 - val_loss: 0.3067 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 119/120
134/133 [==============================] - 26s 196ms/step - loss: 0.2196 - acc: 0.9403 - val_loss: 0.3070 - val_acc: 0.9072
Learning rate:  5e-07
Epoch 120/120
134/133 [==============================] - 26s 192ms/step - loss: 0.2277 - acc: 0.9342 - val_loss: 0.3067 - val_acc: 0.9072
Out[12]:
<tensorflow.python.keras.callbacks.History at 0x2732a352c88>
In [13]:
## Now the training is complete, we get
# another object to load the weights
# compile it, so that we can do 
# final evaluation on it
modelGo.load_weights(filepath)
modelGo.compile(loss='categorical_crossentropy', 
                optimizer='adam', 
                metrics=['accuracy'])
In [14]:
# Make classification on the test dataset
predicts    = modelGo.predict(tsDat)

# Prepare the classification output
# for the classification report
predout     = np.argmax(predicts,axis=1)
testout     = np.argmax(tsLbl,axis=1)
labelname   = ['flower', 'non-flower']
                                            # the labels for the classfication report


testScores  = metrics.accuracy_score(testout,predout)
confusion   = metrics.confusion_matrix(testout,predout)


print("Best accuracy (on testing dataset): %.2f%%" % (testScores*100))
print(metrics.classification_report(testout,predout,target_names=labelname,digits=4))
print(confusion)
Best accuracy (on testing dataset): 91.28%
              precision    recall  f1-score   support

      flower     0.8915    0.9053    0.8984       454
  non-flower     0.9290    0.9184    0.9237       613

    accuracy                         0.9128      1067
   macro avg     0.9103    0.9119    0.9110      1067
weighted avg     0.9131    0.9128    0.9129      1067

[[411  43]
 [ 50 563]]
In [15]:
import pandas as pd

records     = pd.read_csv(modelname +'.csv')
plt.figure()
plt.subplot(211)
plt.plot(records['val_loss'])
plt.plot(records['loss'])
plt.yticks([0, 0.20, 0.30, 0.4, 0.5])
plt.title('Loss value',fontsize=12)

ax          = plt.gca()
ax.set_xticklabels([])



plt.subplot(212)
plt.plot(records['val_acc'])
plt.plot(records['acc'])
plt.yticks([0.7, 0.8, 0.9, 1.0])
plt.title('Accuracy',fontsize=12)
plt.show()
In [16]:
wrong_ans_index = []

for i in range(len(predout)):
    if predout[i] != testout[i]:
        wrong_ans_index.append(i)
In [17]:
wrong_ans_index = list(set(wrong_ans_index))
In [18]:
# Randomly show X examples of that was wrong

dataset = tsDatOrg #flowers #fungus #rocks

for index in wrong_ans_index:
    #index = wrong_ans_index[random.randint(0, len(wrong_ans_index)-1)]
    print("Showing %s index image" %(index))
    print("Predicted as %s but is actually %s" %(predout[index], testout[index]))
    imgplot = plt.imshow(data[index])
    plt.show()
Showing 1025 index image
Predicted as 1 but is actually 0
Showing 3 index image
Predicted as 0 but is actually 1
Showing 522 index image
Predicted as 0 but is actually 1
Showing 12 index image
Predicted as 0 but is actually 1
Showing 1047 index image
Predicted as 1 but is actually 0
Showing 539 index image
Predicted as 0 but is actually 1
Showing 540 index image
Predicted as 0 but is actually 1
Showing 1056 index image
Predicted as 1 but is actually 0
Showing 545 index image
Predicted as 0 but is actually 1
Showing 65 index image
Predicted as 0 but is actually 1
Showing 72 index image
Predicted as 0 but is actually 1
Showing 586 index image
Predicted as 0 but is actually 1
Showing 89 index image
Predicted as 0 but is actually 1
Showing 92 index image
Predicted as 0 but is actually 1
Showing 93 index image
Predicted as 0 but is actually 1
Showing 605 index image
Predicted as 0 but is actually 1
Showing 101 index image
Predicted as 0 but is actually 1
Showing 615 index image
Predicted as 1 but is actually 0
Showing 616 index image
Predicted as 1 but is actually 0
Showing 617 index image
Predicted as 1 but is actually 0
Showing 108 index image
Predicted as 0 but is actually 1
Showing 110 index image
Predicted as 0 but is actually 1
Showing 624 index image
Predicted as 1 but is actually 0
Showing 113 index image
Predicted as 0 but is actually 1
Showing 131 index image
Predicted as 0 but is actually 1
Showing 645 index image
Predicted as 1 but is actually 0
Showing 137 index image
Predicted as 0 but is actually 1
Showing 147 index image
Predicted as 0 but is actually 1
Showing 148 index image
Predicted as 0 but is actually 1
Showing 169 index image
Predicted as 0 but is actually 1
Showing 695 index image
Predicted as 1 but is actually 0
Showing 715 index image
Predicted as 1 but is actually 0
Showing 220 index image
Predicted as 0 but is actually 1
Showing 732 index image
Predicted as 1 but is actually 0
Showing 733 index image
Predicted as 1 but is actually 0
Showing 743 index image
Predicted as 1 but is actually 0
Showing 748 index image
Predicted as 1 but is actually 0
Showing 250 index image
Predicted as 0 but is actually 1
Showing 253 index image
Predicted as 0 but is actually 1
Showing 259 index image
Predicted as 0 but is actually 1
Showing 774 index image
Predicted as 1 but is actually 0
Showing 775 index image
Predicted as 1 but is actually 0
Showing 269 index image
Predicted as 0 but is actually 1
Showing 790 index image
Predicted as 1 but is actually 0
Showing 279 index image
Predicted as 0 but is actually 1
Showing 792 index image
Predicted as 1 but is actually 0
Showing 794 index image
Predicted as 1 but is actually 0
Showing 796 index image
Predicted as 1 but is actually 0
Showing 288 index image
Predicted as 0 but is actually 1
Showing 805 index image
Predicted as 1 but is actually 0
Showing 305 index image
Predicted as 0 but is actually 1
Showing 314 index image
Predicted as 0 but is actually 1
Showing 830 index image
Predicted as 1 but is actually 0
Showing 329 index image
Predicted as 0 but is actually 1
Showing 848 index image
Predicted as 1 but is actually 0
Showing 852 index image
Predicted as 1 but is actually 0
Showing 349 index image
Predicted as 0 but is actually 1
Showing 355 index image
Predicted as 0 but is actually 1
Showing 365 index image
Predicted as 0 but is actually 1
Showing 366 index image
Predicted as 0 but is actually 1
Showing 880 index image
Predicted as 1 but is actually 0
Showing 371 index image
Predicted as 0 but is actually 1
Showing 889 index image
Predicted as 1 but is actually 0
Showing 893 index image
Predicted as 1 but is actually 0
Showing 382 index image
Predicted as 0 but is actually 1
Showing 384 index image
Predicted as 0 but is actually 1
Showing 391 index image
Predicted as 0 but is actually 1
Showing 904 index image
Predicted as 1 but is actually 0
Showing 398 index image
Predicted as 0 but is actually 1
Showing 914 index image
Predicted as 1 but is actually 0
Showing 919 index image
Predicted as 1 but is actually 0
Showing 921 index image
Predicted as 1 but is actually 0
Showing 420 index image
Predicted as 0 but is actually 1
Showing 942 index image
Predicted as 1 but is actually 0
Showing 947 index image
Predicted as 1 but is actually 0
Showing 950 index image
Predicted as 1 but is actually 0
Showing 955 index image
Predicted as 1 but is actually 0
Showing 964 index image
Predicted as 1 but is actually 0
Showing 454 index image
Predicted as 0 but is actually 1
Showing 458 index image
Predicted as 0 but is actually 1
Showing 974 index image
Predicted as 1 but is actually 0
Showing 975 index image
Predicted as 1 but is actually 0
Showing 469 index image
Predicted as 0 but is actually 1
Showing 982 index image
Predicted as 1 but is actually 0
Showing 471 index image
Predicted as 0 but is actually 1
Showing 985 index image
Predicted as 1 but is actually 0
Showing 474 index image
Predicted as 0 but is actually 1
Showing 994 index image
Predicted as 1 but is actually 0
Showing 487 index image
Predicted as 0 but is actually 1
Showing 1007 index image
Predicted as 1 but is actually 0
Showing 498 index image
Predicted as 0 but is actually 1
Showing 1015 index image
Predicted as 1 but is actually 0
Showing 505 index image
Predicted as 0 but is actually 1
In [ ]: